/**
 * 
 */
package com.googlecode.bestpaper.output.pdf.sample;

import java.io.File;

import com.googlecode.bestpaper.output.pdf.book.PDFBook;
import com.googlecode.bestpaper.output.pdf.book.PDFChapter;
import com.googlecode.bestpaper.output.pdf.book.PDFParagraph;
import com.googlecode.bestpaper.output.pdf.book.PDFSection;
import com.googlecode.bestpaper.output.pdf.link.PDFLink;
import com.googlecode.bestpaper.output.pdf.table.PDFCell;
import com.googlecode.bestpaper.output.pdf.table.PDFTable;
import com.googlecode.bestpaper.output.pdf.typeface.PDFBold;
import com.googlecode.bestpaper.output.pdf.typeface.PDFItalic;
import com.googlecode.bestpaper.output.pdf.typeface.PDFStrike;
import com.googlecode.bestpaper.output.pdf.typeface.PDFString;

/**
 * @author xalinx at gmail dot com
 * @date Dec 3, 2009
 */
public class PDFChapterSample {

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		PDFBook book = new PDFBook();
		// chapter 1

		PDFParagraph paragraph1_1 = new PDFParagraph("paragraph 1_1");
		PDFLink image = new PDFLink(
				"src/test/resources/com/googlecode/bestpaper/images/large.png");
		PDFParagraph paragraph1_2 = new PDFParagraph("paragraph 1_2");
		paragraph1_2.addChild(new PDFBold("bold"));
		paragraph1_2.addChild(image);
		paragraph1_2.addChild(new PDFItalic("italic"));
		paragraph1_2.addChild(new PDFStrike("strike"));

		PDFSection section1_1 = new PDFSection("section 1_1");
		section1_1.addChild(paragraph1_1);
		section1_1.addChild(image);
		section1_1.addChild(paragraph1_2);
		section1_1.addChild(paragraph1_1);

		PDFChapter chapter1 = new PDFChapter("chapter 1", 1);
		chapter1.addChild(section1_1);
		book.addChild(chapter1);

		// chapter 2
		PDFCell cellTitle = new PDFCell();
		// PDFParagraph titlePara = new PDFParagraph("test");
		// titlePara.addChild(new PDFBold("标题"));
		// cellTitle.addChild(titlePara);
		cellTitle.addChild(new PDFBold("标题"));
		PDFCell cell = new PDFCell("中文&english");
		int rowNum = 2;
		int columnNum = 5;
		PDFTable table = new PDFTable(columnNum);
		for (int i = 0; i < columnNum; i++) {
			table.addChild(cellTitle);
		}
		for (int i = 0; i < rowNum * columnNum; i++) {
			table.addChild(cell);
		}
		// cell overflow
		table.addChild(cell);
		PDFChapter chapter2 = new PDFChapter("chapter 2 中文", 2);
		chapter2.addChild(new PDFParagraph("中文"));
		PDFSection section2_1 = new PDFSection("section 2.1 中文");
		PDFParagraph paragraph2_1_1 = new PDFParagraph("中文");
		PDFStrike nestTypeface = new PDFStrike();
		nestTypeface.addChild(new PDFBold("blod and strike"));
		nestTypeface.addChild(new PDFItalic("italic and strike"));
		PDFItalic italic = new PDFItalic();
		italic.addChild(new PDFBold("bold and italic and strike"));
		nestTypeface.addChild(italic);
		paragraph2_1_1.addChild(nestTypeface);
		paragraph2_1_1.addChild(new PDFParagraph(" "));
		paragraph2_1_1.addChild(new PDFString(" "));
		paragraph2_1_1.addChild(new PDFString("中文"));
		section2_1.addChild(paragraph2_1_1);
		chapter2.addChild(section2_1);
		PDFSection section2_1_1 = new PDFSection("section 2.1.1 中文");
		section2_1_1.addChild(new PDFParagraph("中文"));
		section2_1_1.addChild(table);
		section2_1.addChild(section2_1_1);
		PDFSection section2_2 = new PDFSection("section 2.2 中文");
		chapter2.addChild(section2_2);
		book.addChild(chapter2);

		book.build(new File("target//PDFChapterSample.pdf"), 0);

	}
}
